﻿using PosClient.Interfaces;
using PosClient.Model;
using PosClient.ViewModel;
using Splat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Concurrency;
using System.Text;
using System.Threading.Tasks;

namespace PosClient.Job.DownLoad
{
    public class DiscountDownLoadJob:IJob
    {
        public Result<JobEntity> Excute()
        {
            Result<JobEntity> result = new Result<JobEntity>()
            {
                Success = true,
                Message = "Discount请求成功"
            };
            var viewModel = Locator.Current.GetService<MainViewModel>();
            viewModel._mainScheduler.Schedule(() =>
            {
                viewModel.SubText = "正在下载削价数据...";
                viewModel.Loading = true;
            });
            var server = Locator.Current.GetService<IPluService>();
            List<PluDiscount> DiscountList = new List<PluDiscount>();
            DiscountList.Add(new PluDiscount()
            {
                Barcode = "2100008654",
                PluCode = "0002818",
                Price = 10,
                StoreCode = "100082",
                StartTime = DateTime.Now,
                EndTime = DateTime.Now.AddDays(7)
            });
            DiscountList.Add(new PluDiscount()
            {
                Barcode = "2100008655",
                PluCode = "0002817",
                Price = 10,
                StoreCode = "100082",
                StartTime = DateTime.Now,
                EndTime = DateTime.Now.AddDays(7)
            });
            DiscountList.Add(new PluDiscount()
            {
                Barcode = "2100008656",
                PluCode = "0002816",
                Price = 10,
                StoreCode = "100082",
                StartTime = DateTime.Now,
                EndTime = DateTime.Now.AddDays(7)
            });
            server.CacheDiscount(DiscountList);
            viewModel._mainScheduler.Schedule(() =>
            {
                viewModel.SubText = string.Empty;
                viewModel.Loading = false;
            });
            return result;
        }
    }
}
